import random

def quicksort(items):
    def partition(lo, hi):
        i = lo
        j = hi
        while j > i:
            while items[i] < items[lo] and i < hi:
                i += 1
            while items[j] >= items[lo] and j > lo:
                j -= 1

            if j > i:
                items[i], items[j] = items[j], items[i]

        items[lo], items[j] = items[j], items[lo]
        return j

    n = len(items)
    if n < 2:
        return

    stack = [(0, n - 1)]

    while stack:
        lo, hi = stack.pop()

        p = partition(lo, hi)

        if p - lo >= 2:
            stack.append((lo, p-1))
        if hi - p >= 2:
            stack.append((p + 1, hi))

if __name__ == '__main__':
    l = [random.randint(0, 100) for x in range(50)]
    # l = [5, 1, 7, 2, 0, 10, 3]
    quicksort(l)
    print(l)

